package com.platform.modules.wallet.controller;

import cn.hutool.core.date.DateUtil;
import com.platform.common.shiro.ShiroUtils;
import com.platform.common.version.ApiVersion;
import com.platform.common.version.VersionEnum;
import com.platform.common.web.domain.AjaxResult;
import com.platform.modules.wallet.domain.WalletNotice;
import com.platform.modules.wallet.service.WalletNoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/wallet")
public class NoticeController {

    @Resource
    private WalletNoticeService noticeService;

    /**
     * 最新公告
     */
    @ApiVersion(VersionEnum.V1_0_0)
    @GetMapping("/getNewNotice")
    public AjaxResult getNewNotice() {

        int hour = DateUtil.thisHour(true);

        if (hour >= 23) {
            return AjaxResult.success(noticeService.getClearNotice());
        }


//        List<WalletNotice> list = noticeService.getList();
//
//        int yu = hour % list.size();

        return AjaxResult.success(noticeService.getNew());
    }

    /**
     * 公告列表
     */
    @ApiVersion(VersionEnum.V1_0_0)
    @GetMapping("/getListNotice")
    public AjaxResult getListNotice() {

        return AjaxResult.success(noticeService.getList());
    }

    /**
     * 公告详情
     */
    @ApiVersion(VersionEnum.V1_0_0)
    @GetMapping("/getNotice/{id}")
    public AjaxResult getNotice(@PathVariable Integer id) {
        return AjaxResult.success(noticeService.getById(id));
    }
}
